﻿using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace 多边形和路径
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private int count = 0;
        private Polygon polygon = null;

        private void Window_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if (count++ == 0)
            {
                polygon = new Polygon();
                polygon.StrokeThickness = 5;
                polygon.Stroke = Brushes.Red;
                canvas.Children.Add(polygon);
            }

            var point = e.GetPosition(canvas);
            polygon.Points.Add(point);
        }

        private void Window_PreviewMouseRightButtonUp(object sender, MouseButtonEventArgs e)
        {
            count = 0;
        }
    }



}